﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dubbo.Example.Consumer
{
    public class CalculatorAction
    {
        private Calculator.Iface calculator;

        public CalculatorAction(Calculator.Iface calculator)
        {
            this.calculator = calculator;
        }

        public void Start()
        {
            //Parallel.For(1, 10000, new ParallelOptions() { MaxDegreeOfParallelism = 6 }, (i) => 
            //{
            //    calculator.ping();
            //    Console.WriteLine("ping({0})", i);
            //});

            calculator.ping();
            Console.WriteLine("ping()");

            int sum = calculator.add(1, 1);
            Console.WriteLine("1+1={0}", sum);

            Work work = new Work();

            work.Op = Operation.DIVIDE;
            work.Num1 = 1;
            work.Num2 = 0;
            try
            {
                //int quotient = calculator.calculate(1, work);
                Console.WriteLine("Whoa we can divide by 0");
            }
            catch (InvalidOperation io)
            {
                Console.WriteLine("Invalid operation: " + io.Why);
            }

            work.Op = Operation.SUBTRACT;
            work.Num1 = 15;
            work.Num2 = 10;
            try
            {
                int diff = calculator.calculate(1, work);
                Console.WriteLine("15-10={0}", diff);
            }
            catch (InvalidOperation io)
            {
                Console.WriteLine("Invalid operation: " + io.Why);
            }

            SharedStruct log = calculator.getStruct(1);
            Console.WriteLine("Check log: {0}", log.Value);
            Console.ReadLine();
        }
    }
}
